---# 读取yaml 和properties 工具使用


--config_load.lua
---tinnyaml.lua

---## 声明 yaml
---



local yaml = require("lualib.zwyaml")


---## 先从本地文件读取文件内容  再用yaml 解携yaml字符串 转成table



local function read_file(path)
    local file, err = io_open(path, "rb")   -- 读取文件
    if not file then
        log.error("failed to read config file:" .. path, ", error info:", err)
        return nil, err
    end

    local content = file:read("*a") -- `读取整个文件
    file:close()
    return content
end


local default_conf_yaml, err = read_file("/Users/zhangzw/Documents/workspace-lua/luademo/src/demo/properties/test.yaml")
if type(default_conf_yaml) ~= "string" then
    return nil, "failed to read config-default file:" .. err
end

local   config_data = yaml.parse(default_conf_yaml)

print(config_data.server.ip)
print(config_data.server.port)


local YamlUtil = require("util.YamlUtil")
local config_data2 = YamlUtil:readFile("/Users/zhangzw/Documents/workspace-lua/luademo/src/demo/properties/test.yaml");
print(config_data2.server.ip)
print(config_data2.server.port)
